package io;

import java.io.IOException;
import java.io.RandomAccessFile;

public class Recorder {

	private RandomAccessFile recordFile;

	public Recorder () throws IOException {
		recordFile = new RandomAccessFile("record", "rws");
	}

	public synchronized double readHighestScore () throws IOException {
		if (recordFile.length() < 8) {
			return 0;
		}
		recordFile.seek(0);
		return recordFile.readDouble();
	}

	public synchronized double readHighestElim () throws IOException {
		if (recordFile.length() < 16) {
			return 0;
		}
		recordFile.seek(8);
		return recordFile.readDouble();
	}

	public synchronized void updateHighestScore (double highest) throws IOException {
		recordFile.seek(0);
		recordFile.writeDouble(highest);
	}

	public synchronized void updateHighestElim (double highest) throws IOException {
		recordFile.seek(8);
		recordFile.writeDouble(highest);
	}

	public synchronized void close () throws IOException {
		recordFile.close();
	}

}
